package com.ruoyi.web.controller.douyinAuthorization;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DouyinAuthorization;
import com.ruoyi.system.service.IDouyinAuthorizationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 抖音授权设置 Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="抖音授权设置")
@RestController
@RequestMapping("/system/douyinAuthorization")
public class DouyinAuthorizationController extends BaseController
{
    @Autowired
    private IDouyinAuthorizationService douyinAuthorizationService;

    /**
     * 通过门店名称查询抖音授权设置列表
     */
    @ApiOperation("通过门店名称查询抖音授权设置列表")
    @PreAuthorize("@ss.hasPermi('system:authorization:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<DouyinAuthorization> list = douyinAuthorizationService.selectDouyinAuthorizationListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出抖音授权设置列表
     */
    @ApiOperation("导出抖音授权设置列表")
    @PreAuthorize("@ss.hasPermi('system:authorization:export')")
    @Log(title = "抖音授权设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<DouyinAuthorization> list = douyinAuthorizationService.selectDouyinAuthorizationListByName(storeName);
        ExcelUtil<DouyinAuthorization> util = new ExcelUtil<DouyinAuthorization>(DouyinAuthorization.class);
        util.exportExcel(response, list, "抖音授权设置数据");
    }

    /**
     * 通过id获取抖音授权设置信息
     */
    @ApiOperation("通过id获取抖音授权设置信息")
    @PreAuthorize("@ss.hasPermi('system:authorization:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(douyinAuthorizationService.selectDouyinAuthorizationById(id));
    }

    /**
     * 新增抖音授权设置
     */
    @ApiOperation("新增抖音授权设置")
    @PreAuthorize("@ss.hasPermi('system:authorization:add')")
    @Log(title = "抖音授权设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DouyinAuthorization douyinAuthorization)
    {
        return toAjax(douyinAuthorizationService.insertDouyinAuthorization(douyinAuthorization));
    }

    /**
     * 修改抖音授权设置列表
     */
    @ApiOperation("修改抖音授权设置")
    @PreAuthorize("@ss.hasPermi('system:authorization:edit')")
    @Log(title = "抖音授权设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DouyinAuthorization douyinAuthorization)
    {
        return toAjax(douyinAuthorizationService.updateDouyinAuthorization(douyinAuthorization));
    }

    /**
     * 通过id批量删除抖音授权设置信息
     */
    @ApiOperation("通过id批量删除抖音授权设置信息")
    @PreAuthorize("@ss.hasPermi('system:authorization:remove')")
    @Log(title = "抖音授权设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(douyinAuthorizationService.deleteDouyinAuthorizationByIds(ids));
    }
}
